#include <iostream>
using namespace std;
// 针对上面的代码我们做出以下改造：
// 1.我们增加一个派生类Derive去继承Base
// 2.Derive中重写Func1
// 3.Base再增加一个虚函数Func2和一个普通函数Func3
class Base
{
public:
    virtual void Func1()
    {
        cout << "Base::Func1()"
             << endl;
    }
    virtual void Func2()
    {
        cout << "Base::Func2()"
             << endl;
    }
    void Func3()
    {
        cout << "Base::Func3()"
             << endl;
    }

private:
    int _b = 1;
};
class Derive : public Base
{
public:
    virtual void Func1()
    {
        cout << "Derive::Func1()" << endl;
    }

private:
    int _d = 2;
};

int main()
{
    int a = 0;
    cout << "栈:" << &a << endl;

    int *p1 = new int;
    cout << "堆:" << p1 << endl;

    const char *str = "hello world";
    // cout可以自动识别类型，强转成指针打印地址
    cout << "代码段/常量区:" << (void *)str << endl;

    static int b = 0;
    cout << "静态区/数据段:" << &b << endl;

    Base be;
    //
    cout << "虚表:" << (void *)*((int *)&be) << endl;

    Base *ptr1 = &be;
    int *ptr2 = (int *)ptr1;
    printf("虚表:%p\n", *ptr2);

    Derive de;
    cout << "虚表:" << (void *)*((int *)&de) << endl;

    Base b1;
    Base b2;

    return 0;
}